blob: 724e8b74cfe7530e1dd58c681164123f15559fac (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
---
import { type CollectionEntry, getCollection } from "astro:content";
import Base from "@layouts/Base.astro";
import BlogCard from "@components/BlogCard.astro";
type Props = { posts: CollectionEntry<"blog">[] };
export async function getStaticPaths() {
const posts = await getCollection("blog");
const keywords = [
...new Set(
await getCollection("blog").then((x) =>
x.flatMap((x) => x.data.keywords)
),
).values(),
];
return keywords.map((k) => ({
params: { slug: k },
props: {
posts: posts.filter((post) =>
post.data.keywords.some((i) => i.localeCompare(k) === 0)
),
},
}));
}
const title = "Blog";
const description = "Latest articles.";
const posts = Astro.props.posts.sort((a, b) =>
new Date(b.data.dateCreated).valueOf() -
new Date(a.data.dateCreated).valueOf()
);
---
<Base {title} {description}>
<main>
<h2>Blogue</h2> {posts.map((post) => <BlogCard {...post} />)}
</main>
</Base>
|